#!/bin/bash
if [ x$1 != x ]
then
  echo "page.sh new page"
  path="src/pages/${1}"
  classname=$(echo "${path##*/}-page" | tr '-' ' ' | awk '{for(i=1;i<=NF;i++) {printf "%s%s ", toupper(substr($i,1,1)),substr($i,2)};printf ORS}' | tr -d ' ')
  mkdir -p $path
  touch "${path}/${classname}.ts"
  touch "${path}/${classname}.vue"
  echo "<template>
  <div>
    <tc-header :title=\"title\"></tc-header>
  </div>
</template>

<script src=\"./${classname}.ts\"></script>" >> "${path}/${classname}.vue"
  echo "import Router from 'vue-router'
import { Component, Emit, Inject, Model, Prop, Provide, Vue, Watch } from 'vue-property-decorator'
import TcHeader from '@/controls/TcHeader.vue'

@Component({
  components: {
    TcHeader
  }
})
export default class ${classname} extends Vue {
  title = '${classname}'
}
" >> "${path}/${classname}.ts"
else
    echo "page.sh unkonw argument. eg. ./page.sh user/info-avatar"
fi